package utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class MoveVisitor implements NodeVisitor {

	public void visit(FileResources fr, File src, File dest) {
		InputStream inStream = null;
		OutputStream outStream = null;

		try{

			inStream = new FileInputStream(src);
			outStream = new FileOutputStream(dest);

			byte[] buffer = new byte[1024];

			int length;
			//copy the file content in bytes 
			while ((length = inStream.read(buffer)) > 0){

				outStream.write(buffer, 0, length);

			}

			inStream.close();
			outStream.close();

			//delete the original file
			src.delete();

		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public void visit(FileResources fr, File f) {}


}
